package com.infore.airsupervise.ui.activity;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.beardedhen.androidbootstrap.AwesomeTextView;
import com.beardedhen.androidbootstrap.BootstrapText;
import com.beardedhen.androidbootstrap.font.FontAwesome;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.infore.airsupervise.R;
import com.infore.airsupervise.bean.QuestionE;
import com.infore.airsupervise.ui.widget.SwipeRecyclerView;
import com.infore.airsupervise.utils.DateUtil;
import com.infore.airsupervise.utils.JumpUtil;
import com.infore.airsupervise.utils.ToastUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @features:  我可以查看的问题上报列表
 * @author: WuTao
 * @date: 2017/4/24 15:26
 */
public class QuestionCheckActivity extends BaseTitleBarActivity implements SwipeRecyclerView.OnActionListener {
    @BindView(R.id.refreshRecyclerView)
    SwipeRecyclerView swipeRecyclerView;
    @BindView(R.id.tv_title)
    AwesomeTextView tvTitle;
    @BindView(R.id.ll_mission)
    LinearLayout llMission;

    private BaseQuickAdapter<QuestionE,BaseViewHolder> adapter;//适配器
    private List<QuestionE> list = new ArrayList<>();//列表集合

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_question_list);
        ButterKnife.bind(this);
        title.setText("我可以查看的问题上报");
        rightMenu.setFontAwesomeIcon(FontAwesome.FA_PLUS);
        initRecycleView();
        //跳转界面的头布局
        addHeaderView();
    }

    /**
     * recycle和适配器 初始化
     */
    private void initRecycleView(){
       adapter = new BaseQuickAdapter<QuestionE, BaseViewHolder>(R.layout.item_inspect_plan, list) {
           @Override
           protected void convert(BaseViewHolder helper, QuestionE item) {
               helper.setText(R.id.tv_time, DateUtil.toShortDate(item.getReleaseTime()))
                       .setText(R.id.tv_title, item.getQuestionTitle())
                       .setText(R.id.tv_content, item.getQuestionAddress());
           }
       };
        swipeRecyclerView.setActionListener(this);
        swipeRecyclerView.setAdapter(adapter);
        // 首次自动刷新
        swipeRecyclerView.getSwipeLayout().setRefreshing(true);
        swipeRecyclerView.onRefresh();

    }
    /**
     * recycleView 添加头部 布局
     */
    private void addHeaderView() {
        llMission.setVisibility(View.VISIBLE);
        llMission.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转
                JumpUtil.jumpFromTo(ctx,QuestionListActivity.class);
            }
        });
        BootstrapText.Builder builder = new BootstrapText.Builder(ctx);
        builder.addFontAwesomeIcon(FontAwesome.FA_USER)
                .addText("  我提交的问题上报");
        tvTitle.setBootstrapText(builder.build());
    }
    /**
     * 刷新
     */
    @Override
    public void onRefresh() {
        swipeRecyclerView.commonSuccessHandle(true,0);

    }

    /**
     * 加载
     */
    @Override
    public void onLoadMore() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                swipeRecyclerView.getAdapter().loadMoreEnd();
                swipeRecyclerView.getSwipeLayout().setEnabled(true);
            }
        }, 1000);
    }

    @Override
    protected void onRightMenuClick(View view) {
        JumpUtil.ForResultJumpFromTo(QuestionCheckActivity.this, QuestionCreateActivity.class,200);
    }
    /**
     * item 点击事件
     * @param adapter
     * @param view
     * @param position
     */
    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

    }
}
